package com.hbnu.dao;

import com.sun.scenario.effect.impl.prism.PrImage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import javax.naming.ldap.PagedResultsControl;


@Repository
public class UserDao {
    @Autowired
    private JdbcTemplate jdbcTemplate;

    public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
        this.jdbcTemplate = jdbcTemplate;
    }

    public void addUser(){
        //System.out.println("在数据里添加用户信息...");

        String sql = "insert into tb_user(name,password,addr,salary) values(?,?,?,?)";
        int row = jdbcTemplate.update(sql, "小敏", "xiaomin", "湖北襄阳", 6666.66);
        System.out.println(row == 1 ? "数据添加成功" : "数据添加失败");
    }

    public void lessMoney(){
        String sql = "update tb_user set salary = salary - ? where name = ?";
        int row = jdbcTemplate.update(sql,1000.00,"黄敏");
        System.out.println(row == 1 ? "转账成功" : "转账失败");
    }

    public void moreMoney(){
        String  sql = "update tb_user set salary = salary + ? where name + ?";
        int row = jdbcTemplate.update(sql, 1000.00, "小敏");
        System.out.println(row == 1 ? "收款成功" : "收款失败");
    }
}
